package main

import (
	"fmt"
	"log"
	"net/rpc/jsonrpc"
)

type RpcError map[string]interface{}

func (r RpcError) Error() string {
	code, ok := r["code"].(int)
	if !ok {
		code = 0
	}
	message, ok := r["message"].(string)
	if !ok {
		message = "Unknown error."
	}
	return fmt.Sprintf("%d: %s.\n", code, message)
}

type Human struct {
	X         int
	Y         int
	IsStudent bool
	UserId    int
}

type RpcArgs struct {
	FileIn  string
	FileOut string
	Humans  []Human
	Radius  int
}

func main() {
	client, err := jsonrpc.Dial("tcp", "localhost:8887")
	if err != nil {
		log.Fatal("dialing:", err)
	}

	humans := make([]Human, 2)
	humans[0] = Human{852, 135, true, 0}
	humans[1] = Human{470, 69, true, 0}

	args := &RpcArgs{
		"2008-jesus-cambridge-lores.jpeg",
		"rpcout.jpg",
		humans,
		10}
	var reply int
	err = client.Call("blur_image", args, &reply)
	client.Close()
	log.Printf("Reply: %v. Error: %v", reply, err)
}
